package com.avic.service.impl;

import com.avic.common.util.ex.BizErrorCode;
import com.avic.common.util.ex.BizException;
import com.avic.dal.condition.EmergencyResourceListCondition;
import com.avic.dal.model.EmergencyResource;
import com.avic.service.EmergencyResourceService;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * @Description
 * @Author huangsheng
 * @Date 2018/10/24 11:45
 */
@Data
@Slf4j
@Service
public class EmergencyResourceServiceImpl extends AbstractServiceImpl implements EmergencyResourceService {

    @Override
    public List<EmergencyResource> emergencyResourceList(EmergencyResourceListCondition emergencyResourceListCondition) {
        return emergencyResourceMapper.itemList(emergencyResourceListCondition);
    }

    @Override
    public int emergencyResourceListTotal(EmergencyResourceListCondition emergencyResourceListCondition) {
        return emergencyResourceMapper.queryRecordsTotal(emergencyResourceListCondition);
    }

    @Override
    public int emergencyNumberCount(String emergencyNumber) {
        return emergencyResourceMapper.queryItemCountByNumber(emergencyNumber);
    }

    @Override
    public String createEmergencyResource(EmergencyResource emergencyResource) {
        try {
            String resourceId = UUID.randomUUID().toString();
            emergencyResource.setId(resourceId);
            emergencyResourceMapper.insert(emergencyResource);
            return resourceId;
        } catch (Exception e) {
            log.error("创建应急资源数据时发生错误 {}", e.getMessage());
            throw new BizException(BizErrorCode.SYSTEM_ERROR);
        }
    }

    @Override
    public EmergencyResource queryEmergencyResourceById(String id) {
        return emergencyResourceMapper.queryItemById(id);
    }

    @Override
    public void updateEmergencyResource(EmergencyResource emergencyResource) {
        try {
            emergencyResourceMapper.update(emergencyResource);
        } catch (Exception e) {
            log.error("修改应急资源数据时发生错误 {}", e.getMessage());
            throw new BizException(BizErrorCode.SYSTEM_ERROR);
        }
    }

    @Override
    public void deleteEmergencyResource(String id) {
        try {
            emergencyResourceMapper.delete(id);
        } catch (Exception e) {
            log.error("删除应急资源数据时发生错误 {}", e.getMessage());
            throw new BizException(BizErrorCode.SYSTEM_ERROR);
        }
    }
}
